﻿@using System.Globalization
@using Abp.Extensions
@using Abp.Web.Mvc.Extensions
@using Microsoft.Owin.Security
@using Akso.MultiTenancy
@model Akso.Web.Models.Account.LoginFormViewModel

@section Scripts
{
    @Html.IncludeScript("~/Views/Account/Login.js")
}

<h3 class="form-title">@L("LogIn")</h3>

<div class="alert alert-danger display-hide">
    <button class="close" data-close="alert"></button>
    <span>
        <i class="fa fa-warning"></i> @L("PleaseEnterLoginInformation")
    </span>
</div>

@if (!Model.SuccessMessage.IsNullOrEmpty())
{
    <div class="alert alert-success">
        <button class="close" data-close="alert"></button>
        <span>
            @Model.SuccessMessage
        </span>
    </div>
}

<form class="login-form" action="@Url.Action("Login")?returnUrl=@ViewBag.ReturnUrl" method="post">
    <input type="hidden" name="returnUrlHash" />
    @if (ViewBag.IsMultiTenancyEnabled)
    {
        if (Model.TenancyName.IsNullOrEmpty())
        {
            <div class="form-group">
                <!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
                <label class="control-label visible-ie8 visible-ie9">@L("TenancyName")</label>
                <input class="form-control form-control-solid placeholder-no-fix input-ltr" type="text" placeholder="@L("TenancyName")" name="tenancyName" maxlength="@Tenant.MaxTenancyNameLength" />
            </div>
        }
        else
        {
            <input type="hidden" name="tenancyName" value="@Model.TenancyName" />
        }
    }
    <div class="form-group">
        <!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
        <label class="control-label visible-ie8 visible-ie9">@L("UserNameOrEmail")</label>
        <input class="form-control form-control-solid placeholder-no-fix" type="text" autocomplete="off" placeholder="@L("UserNameOrEmail")" name="usernameOrEmailAddress" value="@(Model.UserNameOrEmailAddress ?? "")" required />
    </div>
    <div class="form-group">
        <label class="control-label visible-ie8 visible-ie9">@L("Password")</label>
        <input class="form-control form-control-solid placeholder-no-fix" type="password" autocomplete="off" placeholder="@L("Password")" name="password" />
    </div>
    <div class="form-actions">
        <button type="submit" class="btn btn-success uppercase">@L("LogIn")</button>
        <label class="rememberme check">
            <input type="checkbox" name="rememberMe" value="true" />@L("RememberMe")
        </label>
        <a href="@Url.Action("ForgotPassword", "Account")" id="forget-password" class="forget-password">@L("ForgotPassword")</a>
    </div>
</form>

@{
    var loginProviders = Context.GetOwinContext().Authentication.GetExternalAuthenticationTypes().ToList();
    Func<string, string> getSocialIconClass = (provider) =>
    {
        provider = provider.ToLower(CultureInfo.InvariantCulture);

        if (provider == "google")
        {
            return "googleplus";
        }
        
        return provider;
    };
}

@if (loginProviders.Count > 0)
{
    <div class="login-options">
        <h4>@L("LoginWith")</h4>
        <ul class="social-icons">
            @using (Html.BeginForm("ExternalLogin", "Account", method: FormMethod.Post))
            {
                @Html.AntiForgeryToken()
                
                <input type="hidden" name="returnUrl" value="@ViewBag.ReturnUrl" />
                <input type="hidden" name="provider" value="" />
                
                foreach (AuthenticationDescription p in loginProviders)
                {
                    <li>
                        <a class="social-login-icon social-icon-color @getSocialIconClass(p.AuthenticationType)"
                           title="@p.AuthenticationType"
                           data-provider="@p.AuthenticationType" 
                           href="javascript:;"></a>
                    </li>
                }
            }
        </ul>
    </div>
}

<div class="create-account">
    <p>
        @if (Model.IsSelfRegistrationEnabled)
        {
            <a href="@Url.Action("Register", "Account")" id="register-btn" class="uppercase">@L("CreateAnAccount")</a>
            <span class="pipe-divider"> | </span>
        }
        <a href="@Url.Action("EmailActivation", "Account")" id="email-activation-btn" class="uppercase">@L("EmailActivation")</a>
    </p>
</div>